// 获取文章信息
import httpInstance from '@/utils/http'
export const getAllBooks = (params) => {
  return httpInstance({
    url: '/api/book/getAllBooks',
    method: 'get',
    params: params,
  })
}
// 获取文章详情
export const getBookDetail = (bookId) => {
  return httpInstance({
    url: `/api/book/getBookDetail/${bookId}`,
    method: 'get',
  })
}

// 获取章节内容
export const getChapterContent = (chapterId) => {
  return httpInstance({
    url: `/api/book/getChapterContent/${chapterId}`,
    method: 'get',
  })
}

export const getTotalChapters = (bookId) => {
  return httpInstance({
    url: `/api/book/getTotalChapters/${bookId}`,
    method: 'get',
  })
}

// 创建动态
export const saveAnnotationData = (annotationData) => {
  return httpInstance({
    url: '/api/book/saveAnnotation', // 后端创建动态的接口地址
    method: 'post',
    data: annotationData, // 动态数据
  })
}

export const getAnnotations = ({ userId, bookId, chapterId }) => {
  return httpInstance({
    url: `/api/book/getAnnotations/${userId}/${bookId}/${chapterId}`,
    method: 'get',
  })
}

export const getAiSessions = (userId) => {
  return httpInstance({
    url: `/api/book/getAiSessions/${userId}`,
    method: 'get',
  })
}

export const getAiMessages = (sessionId) => {
  return httpInstance({
    url: `/api/book/getAiMessages/${sessionId}`,
    method: 'get',
  })
}

// 创建新会话 API
export const createNewSession = () => {
  return httpInstance({
    url: `/api/book/createNewSession`,
    method: 'post',
  })
}

export const getShelfBook = () => {
  return httpInstance({
    url: '/api/book/getShelfBook',
    method: 'get',
  })
}

export const addBookToShelf = (bookId) => {
  return httpInstance({
    url: '/api/book/addToShelf',
    method: 'post',
    params: { bookId }, // 🔹注意是 params
  })
}

export const removeBookFromShelf = (bookId) => {
  return httpInstance({
    url: '/api/book/removeFromShelf',
    method: 'post',
    params: { bookId }, // or data: { bookId } based on backend
  })
}

export const updateLastReadChapter = (bookId, chapterId) => {
  return httpInstance({
    url: '/api/book/updateLastRead',
    method: 'post',
    params: { bookId, chapterId }, // 或根据后端需要用 data 传递
  })
}
